const { defineConfig } = require('@vue/cli-service')
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin') // 查看耗时
const ProgressBarPlugin = require('progress-bar-webpack-plugin') // 打包进度
const AutoImport = require('unplugin-auto-import/webpack') // 自动导入模块
const Components = require('unplugin-vue-components/webpack') // 自动导入使用的组件
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const chalk = require('chalk')
const name = 'micro-storm'
module.exports = defineConfig({
  publicPath: process.env.NODE_ENV == 'production' ? `/${name}` : '/',
  outputDir: `dist/${name}`,
  productionSourceMap: false,
  transpileDependencies: true,
  lintOnSave: process.env.NODE_ENV !== 'production',
  configureWebpack: () => ({
    cache: {
      type: 'filesystem',
    },
    plugins: [
      new SpeedMeasurePlugin(),
      new ProgressBarPlugin({
        format: `:msg [:bar] ${chalk.green.bold(':percent')} (:elapsed s)`,
      }),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    output: {
      libraryTarget: 'umd',
      library: `${name}-[name]`,
      chunkLoadingGlobal: `webpackJsonp_${name}`,
    },
  }),
  chainWebpack: config => {
    config.plugin('define').tap(definitions => {
      Object.assign(definitions[0], {
        __VUE_OPTIONS_API__: 'true',
        __VUE_PROD_DEVTOOLS__: 'false',
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
      })
      return definitions
    })
  },
  devServer: {
    https: false,
    open: true,
    historyApiFallback: true,
    allowedHosts: 'all',
    client: {
      overlay: false,
    },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    // proxy: {
    //   '/bytserver': {
    //     target: '',
    //     ws: false,
    //     changeOrigin: true,
    //     pathRewrite: {
    //       '^/bytserver': '',
    //     },
    //   },
    // },
  },
})
